package com.jimikongjian.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * Created by fuxiuyang on 17/4/5.
 */
@Service("codeService")
public class CodeService {


//    public static final int CODE_LENGTH = 4;

    @Value("${code.length}")
    private Integer codeLength;

    public String getCode(){
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < codeLength; i ++){
            sb.append(getNum());
        }
        return sb.toString();
    }
    public String getNum(){
        int n = (int)(Math.random()*10);
        return String.valueOf(n);
    }
}
